package com.itheima.web.response;

import org.apache.commons.io.IOUtils;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;

//
@WebServlet("/resp4")
public class ResponseDemo4 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("ResponseDemo4...");
        // 写图片给客户端
        // 1.把磁盘图片文件到到当前内存  读磁盘文件到内存  文件输入流
        FileInputStream fis =
                new FileInputStream("D:\\00_400\\code_400\\webdemo02\\src\\main\\resources\\img\\test.jpg");
        // 2.然后再把文件输入流数据，写入到浏览器的输出流
        ServletOutputStream clientOS = resp.getOutputStream();
        // 使用工具，来完成把输入流的数据，转让到输出流里面去
        IOUtils.copy(fis,clientOS);
        // 关闭流
        fis.close();

    }
}
